<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    HelloWorld
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: HelloWorld.php 6590 2010-06-25 19:40:21Z john $
 * @author     John
 */

/**
 * @category   Application_Extensions
 * @package    HelloWorld
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Testimonial_Model_Testimonial extends Core_Model_Item_Abstract
{
  public function getHref($params = array())
  {
    $slug = $this->getSlug();
    //$viewer = Engine_Api::_()->user()->getViewer();
    //$viewer = $this->viewer->getIdentity();
    $params = array_merge(array(
      'route' => 'testimonial_view',
      'reset' => true,
      'sender_id' => $this->sender_id,
      'id' => $this->testimonial_id,
      'slug' => $slug,
    ), $params);
    $route = $params['route'];
    $reset = $params['reset'];
    unset($params['route']);
    unset($params['reset']);
    return Zend_Controller_Front::getInstance()->getRouter()
      ->assemble($params, $route, $reset);
  }
 
  
  public function getDescription()
  {
    // @todo decide how we want to handle multibyte string functions
    $tmpBody = strip_tags($this->description);
    return ( Engine_String::strlen($tmpBody) > 255 ? Engine_String::substr($tmpBody, 0, 255) . '...' : $tmpBody );
  }
  
   public function getSlug($str = null)
  {
    $str = $this->getTitle();
    if( strlen($str) > 32 ) {
      $str = Engine_String::substr($str, 0, 32) . '...';
    }
    $str = preg_replace('/([a-z])([A-Z])/', '$1 $2', $str);
    $str = strtolower($str);
    $str = preg_replace('/[^a-z0-9-]+/i', '-', $str);
    $str = preg_replace('/-+/', '-', $str);
    $str = trim($str, '-');
    if( !$str ) {
      $str = '-';
    }
    return $str;
  }
}